import requests
import json
if __name__ == '__main__':
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36'
    }
    url = 'http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?'
    params = {
        'type': 'NS',
        'sty': 'NSSH',
        'st': '2',
        'sr': '-1',
        'p': '1',
        'ps': '100',
        'js': 'var vySWIPgL = {pages: (pc), data: [(x)]}',
        'mkt': '1',
        'stat': '1',
        'cmd':'',
        'rt': '53744646'
    }
    response = requests.get(url=url,params=params,headers=headers)
    list_data = response.text
    f = open('上市公司.txt','w',encoding='utf-8')
    # json.dump(list_data,f,ensure_ascii=False)
    f.write(list_data)
    f.close()
    print('爬取完毕！')